﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Pg.BioMedics.SDR.Entities;
using Pg.BioMedics.SDR.Entities.Codes;
using Pg.BioMedics.SDR.Services;
using Pg.BioMedics.SDR.Web.Controls;
using Pg.BioMedics.SDR.Web.Constants;

public partial class Administration_Views_RegisterView : BaseHostedView
{
    #region Fields

    private IManagementService managementService;

    private Person person = new Person();
    private PlayedRole playedRole = new PlayedRole() { RoleCode = RoleCodes.Operational };

    #endregion

    #region Properties

    /// <summary>
    /// Sets managment service instance. Utilized by IoC context for 
    /// managment service delivery to this view
    /// </summary>
    public IManagementService ManagmentService
    {
        set
        {
            this.managementService = value;
        }
    }

    /// <summary>
    /// Gets person
    /// </summary>
    public Person Person
    {
        get
        {
            return this.person;
        }
    }

    /// <summary>
    /// Gets played role
    /// </summary>
    public PlayedRole PlayedRole
    {
        get
        {
            return this.playedRole;
        }
    }

    #endregion

    #region Event handlers   

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void registerLinkButton_Click(object sender, EventArgs e)
    {
        try
        {
            base.UnbindFormData();
            this.managementService.Register(person, playedRole);

            base.Navigate(UsersManagementViews.FinishRegisterView, UsersManagementViews.PersonDetailsView, this.person);
        }
        catch (Exception ex)
        {
            base.Navigate(UsersManagementViews.ErrorView, ex);
        }

    }

    #endregion
}
